package com.springboot.ball.consumer.games;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
    private Integer id;
    private double x;
    private double y;
    private double radius;
    private double speed;
    private boolean isMe;
    private List<Integer> steps;
    private double vx; // 速度分量
    private double vy;
    private double health; // 生命值属性
    private boolean alive; // 存活状态标志

    // 构造函数需要添加health参数
    public Player(Integer id, double x, double y, double radius, double speed, boolean isMe, List<Integer> steps, double vx, double vy) {
        this.id = id;
        this.x = x;
        this.y = y;
        this.radius = radius;
        this.speed = speed;
        this.isMe = isMe;
        this.steps = steps;
        this.vx = vx;
        this.vy = vy;
        this.health = 100; // 初始生命值为100
        this.alive = true; // 初始状态为存活
    }

    /**
     * 检查玩家是否存活
     * @return 存活状态
     */
    public boolean isAlive() {
        return alive && health > 0;
    }

    /**
     * 设置玩家生命值
     * @param health 新的生命值
     */
    public void setHealth(double health) {
        this.health = health;
        // 如果生命值为0或小于0，自动设置为死亡状态
        if (health <= 0) {
            this.alive = false;
            this.health = 0; // 确保不会出现负血量
        }
    }

    public double getHealth() {
        return health;
    }
    
    /**
     * 获取玩家当前剩余生命值百分比
     * @return 剩余生命值百分比(0-100)
     */
    public double getRemainingHealth() {
        return Math.max(0, Math.min(100, health));
    }
    
    /**
     * 标记玩家为死亡状态
     */
    public void kill() {
        this.health = 0;
        this.alive = false;
    }
}
